import django_filters
from rest_framework import filters
from django_filters.rest_framework import DjangoFilterBackend

from goods.models import *


class GoodsTagActivityFilter(django_filters.rest_framework.FilterSet):

    activity_state = django_filters.BaseInFilter(field_name='activity_state', lookup_expr='in')

    class Meta:
        model = GoodsTagActivity
        fields = ('activity_state',)


class GoodsTagActivityLevelRelationFilter(django_filters.rest_framework.FilterSet):

    goods_tag_activity_id = django_filters.BaseInFilter(field_name='goods_tag_activity_id', lookup_expr='in')

    class Meta:
        model = GoodsTagActivityLevelRelation
        fields = ('goods_tag_activity_id',)


class GoodsFilter(django_filters.rest_framework.FilterSet):
    '''商品过滤'''

    create_time_begin = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='gte')
    create_time_end = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='lte')
    merchant_id = django_filters.BaseInFilter(field_name='merchant_id', lookup_expr='in')
    is_launched = django_filters.BaseInFilter(field_name='is_launched', lookup_expr='in')
    order_species = django_filters.BaseInFilter(field_name='order_species', lookup_expr='in')

    class Meta:
        model = Goods
        fields = ('create_time_begin', 'create_time_end', 'merchant_id', 'is_launched', 'order_species')


class LaunchedGoodsFilter(django_filters.rest_framework.FilterSet):
    '''商品过滤'''

    create_time_begin = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='gte')
    create_time_end = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='lte')
    goods_id = django_filters.BaseInFilter(field_name='goods_id', lookup_expr='in')

    class Meta:
        model = LaunchedGoods
        fields = ('create_time_begin', 'create_time_end', 'goods_id')